
import {
    RECEIVE_ADRESS,
    RECEIVE_CATEGORYS,
    RECEIVE_SHOPLIST,
    RECEIVE_USER
} from './mutations-type'
import { getAddress, getFoodCategorys, getShopList } from '../api/index'
//通过操作mutations间接操作state中的状态，一般用来进行异步操作
export default {
    getAddress({ commit, state }) {
        let geohash = state.latitude + ',' + state.longitude
        getAddress(geohash).then(res => {
            const address = res.data
            commit(RECEIVE_ADRESS, { address })
        })
    },
    getFoodCategorys({ commit }) {
        getFoodCategorys().then(res => {
            const categorys = res.data
            commit(RECEIVE_CATEGORYS, { categorys })
        })
    },
    getShopList({ commit, state }) {
        getShopList(state.longitude, state.latitude).then(res => {
            const shoplist = res.data
            commit(RECEIVE_SHOPLIST, { shoplist })
        })
    },
    getUserInfo({ commit }, uesrInfo) {
        commit(RECEIVE_USER,uesrInfo)
    }

}